package org.example.basic.lambda.stream;

import java.util.*;

/**
 * 〈stream表达式的运用〉<br>
 *
 * @author Mr.Wang
 * @create 2022/1/9
 */
public class Stream {

    /**
     * @Author Mr.Wang
     * @Description 传统的forEach循环
     **/
    public static void pt() {
        List<String> list = Arrays.asList("张三", "张三丰", "成龙", "周星驰");
        List<String> list1 = new ArrayList<>();
        //找出姓张的名字
        for (String s : list) {
            if (s.startsWith("张")) {
                list1.add(s);
            }
        }
        //找出三个字的用户
        List<String> list2 = new ArrayList<>();
        for (String s : list1) {
            if (s.length() == 3) {
                list2.add(s);
            }
        }
        for (String s : list2) {
            System.out.println("输出姓张的名字：" + s);
        }
    }

    /**
     * @Author Mr.Wang
     * @Description StreamAPI：获取流，过滤数据，过滤长度，逐一打印，代码相比于传统的foreach更加简介美观
     **/
    public static void stream() {
        List<String> list = Arrays.asList("张三", "张三丰", "成龙", "周星驰");
        list.stream()
                .filter(s -> s.startsWith("张"))
                .filter(s -> s.length() == 3)
                .forEach(System.out::println);//Lambda表达式
        //stream循环打印数据
        list.stream().forEach(System.out::println);
    }

    /**
     * @Author Mr.Wang
     * @Description stream 两种获取方式
     **/
    public static void StreamCollection() {
        List<String> list = new ArrayList<>();
        list.stream();
        Set<String> set = new HashSet<>();
        set.stream();
        Vector<String> vector = new Vector<>();
        vector.stream();

        /**
         * Map使用stream实现Collection接口
         */
        Map<String, Objects> map = new HashMap<>();
        var stream = map.keySet().stream();//key
        var stream1 = map.values().stream();//value
        var stream2 = map.entrySet().stream();//entry
    }

    /**
     * @Author Mr.Wang
     * @Description stream使用of (咩有这个of方法暂时不写)
     **/
    public static void StreamOF() {

    }

    //测试用例
    public static void main(String[] args) {
        pt();
        stream();
    }

}